package com.tan.api.controller.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tan.common.dto.user.GroupCreateDTO;
import com.tan.common.dto.user.GroupUpdateDTO;
import com.tan.common.query.user.GroupQuery;
import com.tan.common.vo.user.GroupVO;
import com.tan.core.response.ApiResponse;
import com.tan.user.service.ISysGroupService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色和菜单关联表 前端控制器
 * </p>
 *
 * @author Tan
 * @since 2025-01-27
 */
@RestController
@RequestMapping("/sys/group")
public class SysGroupController {

    @Resource
    private ISysGroupService groupService;

    @GetMapping("/pages")
    public ApiResponse<IPage<GroupVO>> pages(GroupQuery groupQuery) {
        return ApiResponse.success(groupService.groupPages(groupQuery));
    }

    @GetMapping("/groups")
    public ApiResponse<List<GroupVO>> groupList(GroupQuery groupQuery) {
        return ApiResponse.success(groupService.groupList());
    }

    @PostMapping("/create")
    public ApiResponse<Void> create(@RequestBody GroupCreateDTO createDTO) {
        groupService.createGroup(createDTO);
        return ApiResponse.success();
    }

    @PostMapping("/update")
    public ApiResponse<Void> update(@RequestBody GroupUpdateDTO updateDTO) {
        groupService.updateGroup(updateDTO);
        return ApiResponse.success();
    }

    @PostMapping("/del/{groupId}")
    public ApiResponse<Void> del(@PathVariable("groupId") Long groupId) {
        groupService.delGroup(groupId);
        return ApiResponse.success();
    }


}
